package com.lsu.app.mapper;

import com.lsu.app.bean.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 *
 * @description 针对表【user】的数据库操作Mapper
 * @Date 2023-10-16 19:31:42
 * @author hjj
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {
//    @Select("select `name` from role where id in(" +
//            "select role_id from user_role where user_id = #{id} )")
//    List<String> selectAllById(@Param("id") Integer id);
    @Select("select * from user where username = #{username}")
    User getUserByUsername(String username);
    @Select("select `name` from role where id in (select role_id from user_role where user_id in (select id from user where username = #{username}) )")
    String getRoleByUsername(String username);
    @Select("select id from user where username = #{username}")
    Integer getIdByUsername(String username);
    @Insert("insert into user_role value(null,#{userId},#{type})")
    void setRoleByUser(@Param("userId") Integer userId,@Param("type")Integer type);
    @Select("select * from user where id in(select user_id from user_role where role_id = #{type}) and username = #{username} and state = 1")
    User getUserByUsernameType(@Param("username") String username,@Param("type") Integer type);
    @Select("select `name` from user where id = #{id}")
    String getNameById(Integer id);
    @Select("select `name` from user_taste where user_id=#{id}")
    List<String> getTasteById(Integer id);

    @Select("select `name` from kv_code where type=1 and value>0")
    List<String> getTastes();
    @Select("select value from kv_code where type=1 and `name`=#{tasteName}")
    Integer getTasteNameValueByTasteName(String tasteName);//获取类型id

    @Select("select id from user where name like #{name}")
    List<Integer> getIdsByName(String name);
    @Select("select COUNT(*) from user_role where user_id=#{id} and role_id=2")
    Integer isTeacher(Integer id);

}




